<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            border: 1px solid #000;
        }
        body>div{
            width: 200px;
            height: 700px;
        }
        .head{
            background-color: #00bfe5;
            font-weight: bolder;
            text-align: center;
            font-size: 20px;
            cursor:pointer;
            height: 30px;
            line-height: 30px;
        }
        .body{
            background-color: ivory;
            height: 100px;
            text-align: center;
            line-height: 30px;
            display: none;
        }
        #black{
            display: block;
        }
    </style>
    <script>
        // function showBody(divID){
        //     var headObj=document.getElementById(divID);
        //     if (headObj.style.display==="block"){//如果display是block变为none
        //         headObj.style.display="none";
        //     }else{//否则变为block
        //         headObj.style.display="block";
        //     }
        // }
        var blackObj;
        window.onload= function (){
            blackObj=document.getElementById("black");
        }
        function showBody(divId){
            //正在显示的div隐藏
            blackObj.style.display="none";
            //得到指定id对应div对象
            var divObj= document.getElementById(divId);
            divObj.style.display="block";
            blackObj=divObj;
        }

    </script>
</head>
<body>
  <div>
    <div class="head" onclick="showBody('friend')">好友</div>
      <div class="body" id="friend">
          张无忌 <br>
          金毛狮王 <br>
          赵敏
      </div>
      <div class="head" onclick="showBody('parent')">亲人</div>
      <div class="body" id="parent">
          胡歌 <br>
          霍建华 <br>
          杨幂
      </div>
      <div class="head" onclick="showBody('black')">黑名单</div>
      <div class="body" id="black">
          吴亦凡 <br>
          郑爽 <br>
          吴秀波
      </div>
  </div>
</body>
</html>